﻿--[[
   @brief    unlock_branch control
   @author   jeffrywang
   @version  1.0
   @date     2017/02/14
--]]


unlock_branch_control = {  
    callback_ = nil;
    branch_info_ = nil;

    init = function()
      ierd_tgp.tpf_ui.Require("unlock_branch\\view.lua");
      
      comm_center.reg_service("Srv_ShowUnlockBranchDlg", "unlock_branch_control.show_unlock_branch_dlg");
    end;

    close = function(event_id, data)
        base_utility.log("[unlock_branch_control]close");
        unlock_branch_view.close_dlg();
    end;
    
    async_check = function(event_id, data)
        base_utility.log("[unlock_branch_control]check");
    end;
    
    unlock_branch_check = function()
        local token = unlock_branch_view.get_code();
        local game_lib = base_utility.get_component_adapter("IGame_library",
            "ierd_tgp.game_library.Get_game_library_adapter();");

        if game_lib ~= nil and 
            game_lib:IsValidBranchToken(branch_info_.game_id, branch_info_.branch_id, token) then
            unlock_branch_view.close_dlg();
            -- 保存密码
            game_lib:SaveBranchToken(branch_info_.game_id, branch_info_.branch_id, token);
            
            local server_id = 0;
            local game_servers = banner_model.get_game_servers(branch_info_.game_id);
            if game_servers ~= nil then
                server_id = game_servers.selleted;
            end
            game_lib:launch_game(branch_info_.game_id, server_id, login_model.main_uin,
                ierd_tgp.game_library.LAUNCH_OP_FROM_LANDING_PAGE, "3100081-1", ierd_tgp.game_library.ZONE_TYPE_FORMAL, 0);
        else
          -- 显示错误
            unlock_branch_view.show_error(TRUE);
        end;
    end;
    
    show_unlock_branch_dlg = function(param)
        base_utility.log("[unlock_branch_control]show_unlock_branch_dlg");
        branch_info_ = param;
        unlock_branch_view.show_dlg(branch_info_);
    end;
};

unlock_branch_control.init();
